/*
 * Copyright (c) 2023 Cshoo Org. All Rights Reserved.
 */

package org.cshoo.tattoo.authorize.api;

import lombok.extern.slf4j.Slf4j;
import org.cshoo.tattoo.authorize.api.dto.AddMicroserviceReq;
import org.cshoo.tattoo.authorize.api.dto.UpdateMicroserviceReq;
import org.cshoo.tattoo.authorize.app.MicroserviceAppService;
import org.cshoo.tattoo.authorize.domain.po.Microservice;
import org.cshoo.tattoo.embed.infra.entity.Response;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author 杨翼
 * @since 1.0
 */
@Slf4j
@RestController
@RequestMapping(value = "/microservice")
public class MicroserviceController {

    @Resource
    private MicroserviceAppService microserviceAppService;

    @RequestMapping(value = "/add", method = RequestMethod.POST)
    public Response<?> addMicroservice(@RequestBody AddMicroserviceReq addMicroserviceReq) {
        microserviceAppService.addMicroservice(addMicroserviceReq);
        return Response.builder().build();
    }

    @RequestMapping(value = "/update", method = RequestMethod.PUT)
    public Response<?> updateMicroservice(@RequestBody UpdateMicroserviceReq updateMicroserviceReq) {
        microserviceAppService.updateMicroservice(updateMicroserviceReq);
        return Response.builder().build();
    }

    @RequestMapping(value = "/delete/{id}", method = RequestMethod.DELETE)
    public Response<?> deleteMicroservice(@PathVariable("id") Long id) {
        log.info("id:{}",id);
        microserviceAppService.deleteMicroservice(id);
        return Response.builder().build();
    }

    @RequestMapping(value = "/all", method = RequestMethod.GET)
    public List<Microservice> findAllMicroservice() {
        log.info("findAllMicroservice");
        return microserviceAppService.findAllMicroservice();
    }
}
